﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using GalaxyTranslator.EntityDataModel;
using GalaxyTranslator.Model;
using GalaxyTranslator.ViewInterfaces;

namespace GalaxyTranslator.Presenters
{
	public class AdminRegPresenter : BasePresenter<IAdminRegistration>
	{
		public AdminRegPresenter(IAdminRegistration view) : base(view)
		{
		}

		public void InitView(bool isPostBack)
		{
			if (!isPostBack)
			{
				SetAllRoles();
			}
		}

		public void SetAllRoles()
		{
			View.Roles = DataLayer.GetAllRoles();
		}

		public void Register()
		{
			string username = View.UserName;
			string pass = View.Password;
			Role role = DataLayer.GetRoleById(View.RoleId);
			Membership.CreateUser(username, pass);
			Roles.AddUserToRole(username, role.Name);
		}
	}
}